package com.kimoge.spring6.jdbc.xmlbook.service;

import com.kimoge.spring6.jdbc.xmlbook.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author kimoge
 * @date 2025/8/29
 * @description
 */
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
    public int buyBook(int userId, int bookId) {
        // 查找书籍价格
        int price = bookDao.getPriceByBookId(bookId);
        // 书籍数-1
        bookDao.updateStock(bookId);
//        int a = 1/0;
        // 用户现金-书籍价格
        return bookDao.updateBalance(userId, price);
    }
}
